Does using str in the above statement change the information in it?
No. Using the information does not change it. This is the same as with primitive variables: using them (in an arithmetic expression, say) does not change their information.
Here is a slightly larger version of the example program, now with a new variable of a primitive type:
class egString2
{
public static void main ( String[] args )
{
String str;
long value;
str = new String( "The Gingham Dog" );
value = 32912;
System.out.println( str );
System.out.println( value );
}
}
|
When the statement
str = new String( "The Gingham Dog" );
is executed, a new object is created and a reference to it is placed in str.
The variable str now refers to the String object.